﻿
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS数据间的计算法则——运算符</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="renderer" content="webkit">
<meta property="qc:admins" content="77103107776157736375" />
<meta property="wb:webmaster" content="c4f857219bfae3cb" />
<meta http-equiv="Access-Control-Allow-Origin" content="*" />
<meta http-equiv="Cache-Control" content="no-transform " />
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline' 'unsafe-eval' *.imooc.com *.mukewang.com *.baidu.com *.sina.com.cn *.bootcss.com">
<meta name="Keywords" content=",WIKI,手册,编程,知识点,慕课网,imooc" />
<meta name="Description" content="" />

    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=yes"/>







<link rel="stylesheet" href="css/moco.min_1.css" type="text/css" />

<script type="text/javascript">

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('!4(){3 6=a;3 l=4(){3 b,e=9 y("(^| )"+"c=([^;]*)(;|$)");j(b=h.g.z(e)){k w(b[2])}x{k a}};3 8=4(t){3 f=l();3 7=9 o();7.A(7.d()+B*i*i*r);h.g="c="+t+";s="+7.M()+";N=/;L=O.m";j(t&&t!=f){Q.P.G()}};3 5=9 E();5.H=4(){K(6);6=a;8(0)};5.J=4(){8(1)};6=I(4(){5.n="";8(1)},F);5.n=\'R://p.u.m/p/v/q/D.C?t=\'+9 o().d()}()',54,54,'|||var|function|imgobj|timer|exp|setcookie|new|null|arr|IMCDNS|getTime|reg|_0|cookie|document|60|if|return|getcookie|com|src|Date|static|common|1000|expires||mukewang|img|unescape|else|RegExp|match|setTime|24|png|logo|Image|3000|reload|onload|setTimeout|onerror|clearTimeout|domain|toGMTString|path|imooc|location|window|http'.split('|'),0,{}))

</script>


<script type="text/javascript">

var OP_CONFIG={"module":"wiki","page":"detail"};
var isLogin = 0;
var is_choice = "";
var seajsTimestamp="v=201705081743";
var _msg_unread = 0; 
var _not_unread = 0; 
var _cart_num = 0;
</script>






<link rel="stylesheet" href="css/a30fe9388e1b452186c7b33fbd980afe.css" type="text/css" />
</head>
<body >

<div id="header">
    <div class="page-container" id="nav">
        <div id="logo" class="logo"><a href="/" target="_self" class="hide-text" title="首页">慕课网</a></div>


        <button type="button" class="navbar-toggle visible-xs-block js-show-menu" >
            <i class="icon-menu"></i>
        </button>
        <ul class="nav-item">
                        <li class="set-btn visible-xs-block"><a href="/user/newlogin" target="_self">登录</a> / <a href="/user/newsignup" target="_self">注册</a></li>
                        
            <li>
                <a href="/course/list"  target="_self">课程</a>
            </li>
            <li><a href="http://class.imooc.com" class="program-nav " target="_self">职业路径<i class="icn-new"></i></a></li>
            <li>
                <a href="http://coding.imooc.com" target="_self">实战</a>
            </li>
            <li><a href="/wenda"  target="_self">猿问</a></li>
            <li><a href="/article"  target="_self">手记</a></li>
            
        </ul>
                <div id="login-area">
            <ul class="header-unlogin clearfix">
                <li class="shop-cart" id="shop-cart">
                    <a href="http://order.imooc.com/pay/cart" class="shop-cart-icon" target="_blank">
                        <span class="icon-shopping-cart js-endcart"></span>
                        <span class="shopping_icon js-cart-num" data-ordernum="0"  data-cartnum="0" style='display: none'>0</span>
                        <span>购物车</span>
                    </a>
                    <div class="my-cart" id="js-my-cart"></div>
                </li>
                <li class="header-signin">
                    <a href="#" id="js-signin-btn">登录</a>
                </li>
                <li class="header-signup">
                    <a href="#" id="js-signup-btn">注册</a>
                </li>
            </ul>
        </div>
                <div class='search-warp clearfix' style='min-width: 32px; height: 60px;'>
                            <div class="pa searchTags" >
                                    <a href="http://class.imooc.com/sc/20" target="_blank">前端小白</a>
                                    <a href="http://class.imooc.com/sc/22" target="_blank">PHP入门</a>
                                </div>
            
            <div class="search-area" data-search="top-banner">
                <input class="search-input" data-suggest-trigger="suggest-trigger"      type="text" autocomplete="off">
                <input type='hidden' class='btn_search' data-search-btn="search-btn" />
                <ul class="search-area-result" data-suggest-result="suggest-result">
                </ul>
            </div>
            <div class='showhide-search' data-show='no'><i class='icon-search'></i></div>
        </div>
    </div>
</div>

<div class="bindHintBox js-bindHintBox hide">
    <div class="pr">
        为了账号安全，请及时绑定邮箱和手机<a href="/user/setbindsns" class="ml20 color-red" target="_blank">立即绑定</a>
        <button  class="closeBindHint js-closeBindHint" type="button"></button>
        <div class="arrow"> </div>
    </div>
</div>


<div id="main">

<div class="container clearfix">
    <div class='column'>
<!--         <div class="qa-breadcrumb">
                                        <a href="/wiki/category/cid/6">JavaScript</a>
                                    &nbsp;&gt;&nbsp;
                                            <a href="/wiki/category/cid/114">JS 基础</a>
                                                </div> -->
        
        <div class='title clearfix'>
            <span class='text'>JS数据间的计算法则——运算符</span>
            
                    </div>
        
<!--         <div class='tags clearfix'>
                                    <a href='/wiki/tag/id/721' target='_blank' class='nexus-label'>运算优先级</a>
                        <a href='/wiki/tag/id/719' target='_blank' class='nexus-label'>赋值运算符</a>
                        <a href='/wiki/tag/id/717' target='_blank' class='nexus-label'>条件运算符</a>
                        <a href='/wiki/tag/id/715' target='_blank' class='nexus-label'>逻辑运算符</a>
                        <a href='/wiki/tag/id/713' target='_blank' class='nexus-label'>位运算符</a>
                        <a href='/wiki/tag/id/711' target='_blank' class='nexus-label'>比较运算符</a>
                        <a href='/wiki/tag/id/709' target='_blank' class='nexus-label'>算数运算符</a>
                        <a href='/wiki/tag/id/707' target='_blank' class='nexus-label'>运算符</a>
                        <a href='/wiki/tag/id/705' target='_blank' class='nexus-label'>计算法则</a>
                                    
                        <div id='js-supportbox' class='supportbox'>
                <i class='icon-thumb'></i>
                            <span class='text'>0</span>
                <span class="js-add1 add1">+1</span>
                <span class="js-add2 add1">-1</span>
            </div>
        </div> -->
        
        <div id='content' class='content'>
            <p><span style="line-height: 1.76em;">&nbsp; &nbsp; 在JavaScript程序中，要完成各种各样运算是离不开运算符的，运算符用于将一个或几个值进行运算，而得出运算的结果。</span></p><p><span style="line-height: 1.76em;">&nbsp; &nbsp; 在JavaScript中，按照运算类型，可以分为：算数运算符、比较运算符、赋值运算符、逻辑运算符和条件运算符。</span></p><p><span style="line-height: 1.76em;">1、算数运算符</span></p><p><span style="line-height: 1.76em;">JavaScript中提供的算数运算符有：+ &nbsp;、 &nbsp;- &nbsp;、 &nbsp;* &nbsp;、 / &nbsp;、 % &nbsp;、++ &nbsp;、 &nbsp;-- &nbsp;七种，分别表示：加、减、乘、除、求余、自加、自减。</span></p><p><span style="line-height: 1.76em;">其中，+ &nbsp;- &nbsp;* &nbsp;/ &nbsp;%五种为二元运算符，表示对运算符左右两边的操作数做算数运算，运算规则和数学中的运算规则相同。</span></p><p><span style="line-height: 1.76em;">2、比较运算符</span></p><p><span style="line-height: 1.76em;">比较运算符用于对运算的两个表达式进行比较，然后根据比较结果返回布尔类型的值true或false。</span></p><ul class=" list-paddingleft-2" style="list-style-type: disc;"><li><p><span style="line-height: 1.76em;">&nbsp;== &nbsp; &nbsp;判断两边表达式是否相等，当左右相等时，返回值true</span></p></li><li><p><span style="line-height: 1.76em;">！= &nbsp; &nbsp;判断左边表达式是否不等于右边表达式，当左右不相等时，返回值true&nbsp;</span></p></li><li><p><span style="line-height: 1.76em;">&nbsp;&gt; &nbsp; &nbsp; &nbsp; 判断左边表达式是否大于右边表达式</span></p></li><li><p><span style="line-height: 1.76em;"> &nbsp;&gt;= &nbsp; &nbsp;判断左边表达式是否大于等于右边的表达式</span></p></li><li><p>&nbsp;&lt; &nbsp; &nbsp; &nbsp; 判断左边的表达式是否小于右边的表达式</p></li><li><p>&lt;= &nbsp; &nbsp; 判断左边的表达式是否小于等于右边的表达式</p></li></ul><p>3、位运算符</p><p>为运算符就是对数据按二进制位进行运算的运算符。</p><ul class=" list-paddingleft-2" style="list-style-type: disc;"><li><p>&amp; &nbsp; &nbsp;与运算，操作数中的两个位都是1，则结果为1，两个位中有一个为0，则结果为0</p></li><li><p>| &nbsp; &nbsp; &nbsp;或运算，操作数中的两个位都是0，则结果为0，两个位中有一个为1，则结果为1</p></li><li><p>^ &nbsp; &nbsp;异或运算，两个操作位相同时结果为0，不同时结果为1</p></li><li><p>~ &nbsp; &nbsp;取补运算，操作数的各个位取其反，即1变成0, &nbsp;0变成1</p></li><li><p>《 &nbsp; 左位移，操作数按位左移，高位被丢弃，低位顺序补0</p></li><li><p>&nbsp; 》 右位移，操作数按位右移，低位被丢弃，其他各个顺序依次右移</p></li></ul><p>4、逻辑运算符</p><p>逻辑运算通常用于执行布尔运算，常与比较运算符一起使用，来表示复杂比较运算。</p><p>&amp;&amp; &nbsp; 逻辑与 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|| &nbsp;逻辑或 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;！ &nbsp;逻辑非</p><p>（这三个逻辑运算符，比较简单就不详细介绍了，相信大家都会的，嘿嘿……）</p><p>5、条件运算符</p><ol class=" list-paddingleft-2" style="list-style-type: decimal;"><li><p>= &nbsp; &nbsp;将右边的表达式的值赋给左边的变量</p></li><li><p>+= &nbsp; &nbsp;将运算符左边的值加上右边表达式的值，然后再赋给左边的变量。a += b 相当于 a =a + b</p></li><li><p>-= &nbsp; &nbsp; 将运算符左边的值减去右边表达式的值，然后再赋给左边的变量。a -= b 相当于 a =a &nbsp;- &nbsp;b</p></li><li><p>*= &nbsp; &nbsp;将运算符左边的值乘以右边表达式的值，然后再赋给左边的变量。a *= b 相当于 a =a * b</p></li><li><p>/= &nbsp; &nbsp;将运算符左边的值除以右边表达式的值，然后再赋给左边的变量。a /= b 相当于 a =a / b</p></li><li><p>%= &nbsp; 将运算符左边的值对右边表达式的值求余，然后再赋给左边的变量。a %= b 相当于 a =a % b</p></li></ol><p>（注意：书写复合赋值运算符时，两个符号之间一定不能有空格，否则会出错）</p><p><br/></p><p>我对JavaScript运算符的总结就这些了，以上内容均是个人经验总结所得，如有错误请斧正。</p>
        </div>
        
        <div class='refer'>
                        <ul class='clearfix'>
                <li>贡献者：</li>
                                <li><span>zhangyudemuke</a></span>
                            </ul>
        </div>
        
        <div class='share-box clearfix'>
            <div id='' class="bdsharebuttonbox baidufenxiang fl">
                <div class="clearfix" data-bd-bind="1450064771355">
                    <span>分享</span>
                    <a href="javascript:;" title='微信' class="share wx js-share icon-share-weichat" data-cmd="weixin"></a>
                    <a href="javascript:;" title='QQ空间' class="share qq js-share icon-share-qq" data-cmd="qzone"></a>
                    <a href="javascript:;" title='新浪微博' class="share sina js-share icon-share-weibo" data-cmd="tsina"></a>
                    
                    <!--
                    <b class='b'></b>
                    <a href='javascript:;' class='share2 pocket'></a>
                    <a href='javascript:;' class='share2 instapaper'></a>
                    <a href='javascript:;' title='印象笔记' class='share2 evernotecn' data-cmd="evernotecn"></a>
                    <a href='javascript:;' title='有道笔记' class='share2 youdao' data-cmd="youdao"></a>
                    -->
                </div>
            </div>
            
            <div class='fr'><a href='javascript:;' class='js-correction-btn'>内容有误，我要纠错</a></div>
        </div>
        
        <div id='errorCorrection' class='error-correction'>
            <textarea class='textarea js-error_content' maxlength="300" placeholder='请在此输入有误内容'></textarea>
            <textarea class='textarea js-correct_content' maxlength="300" placeholder='请在此输入正确内容，替换有误内容，限300字之内'></textarea>
            <div class='clearfix submit-box'>
                <span class='submit'>提交</span>
                <span class='cancel'>取消</span>
            </div>
        </div>
        
<!--         <div class='other clearfix'>
            <div class='other-left'>
                                <span>上一条</span>
                <a href='/wiki/detail/id/3907'>语法糖 编译原理 编程语言</a>
                            </div>
            <div class='other-right'>
                                <span>下一条</span>
                <a href='/wiki/detail/id/3925'>c++对象this指针</a>
                            </div>
        </div> -->
    </div>
    
    
    
    <div class='sidebar'>
        <div class='js-sidetop'>
<h2 class='title'>相关课程</h2>
    <div class='course-item'>
        <a href='/view/62' target='_blank'>
            <img src='picture/574673940001426706000338-280-160.jpg' />
        </a>
        <a href='/view/62' class='text' target='_blank'>
            信息排列效果
        </a>
    </div>
    <div class='course-item'>
        <a href='/view/35' target='_blank'>
            <img src='picture/52e22c4200016e6e06000338-280-160.jpg' />
        </a>
        <a href='/view/35' class='text' target='_blank'>
            用Socket.io打造协作应用
        </a>
    </div>
    <div class='course-item'>
        <a href='/view/709' target='_blank'>
            <img src='picture/57badee70001709706000338-280-160.jpg' />
        </a>
        <a href='/view/709' class='text' target='_blank'>
            移动端Web组件-Dialog对话框
        </a>
    </div>
</div>
















    </div>
</div>
<input type='hidden' value='3915' id='wikiid' />
<input type='hidden' value='0' id='isSupport' />
<input type='hidden' value='0' id='isLogin' />

<div id='Prompt-layer' class='Prompt-layer'>
	<div class='clearfix Prompt-succ-layer Prompt-error-layer'>
		<i class='Prompt-layer-icon'></i>
		<span class='Prompt-layer-text'></span>
	</div>
</div>

</div>

<div id="footer" >
    <div class="waper">
        <div class="footerwaper clearfix">
            <div class="followus r">
                <a class="followus-weixin" href="javascript:;"  target="_blank" title="微信">
                    <div class="flw-weixin-box"></div>
                </a>
                <a class="followus-weibo" href="http://weibo.com/u/3306361973"  target="_blank" title="新浪微博"></a>
                <a class="followus-qzone" href="http://user.qzone.qq.com/1059809142/" target="_blank" title="QQ空间"></a>
            </div>
            <div class="footer_intro l">
                <div class="footer_link">
                    <ul>
                        <li><a href="http://www.imooc.com/" target="_blank">网站首页</a></li>
                        <li><a href="/about/cooperate" target="_blank" title="企业合作">企业合作</a></li>
                        <li><a href="/about/job" target="_blank">人才招聘</a></li>
                        <li> <a href="/about/contact" target="_blank">联系我们</a></li>
                        <li> <a href="/about/recruit" target="_blank">讲师招募</a></li>
                        <li> <a href="/about/faq" target="_blank">常见问题</a></li>
                        <li> <a href="/user/feedback" target="_blank">意见反馈</a></li>
                        <li><a href="http://daxue.imooc.com/" target="_blank">慕课大学</a></li>
                        <li> <a href="/about/friendly" target="_blank">友情链接</a></li>
                       <!--  <li><a href="/corp/index" target="_blank">合作专区</a></li>
                        <li><a href="/about/us" target="_blank">关于我们</a></li> -->
                    </ul>
                </div>
                <p>Copyright © 2017 imooc.com All Rights Reserved | 京ICP备 13046642号-2</p>
            </div>
        </div>
    </div>
</div>


<div id="J_GotoTop" class="elevator">

    <a href="/user/feedback" class="elevator-msg" target="_blank">
        <i class="icon-feedback"></i>
        <span class="">意见反馈</span>
    </a>
    <a href="/about/faq" class="elevator-faq" target="_blank">
        <i class="icon-ques"></i>
        <span class="">常见问题</span>
    </a>
    <a href="http://www.imooc.com/mobile/app" target="_blank" class="elevator-app" >
        <i class="icon-appdownload"></i>
        <span class="">APP下载</span>
        <div class="elevator-app-box"></div>
    </a>
    <a href="javascript:void(0)" class="elevator-weixin no-goto" id="js-elevator-weixin" >
        <i class="icon-wxgzh"></i>
        <span class="">官方微信</span>
        <div class="elevator-weixin-box"></div>
    </a>
    <a href="javascript:void(0)" class="elevator-top no-goto" style="display:none" id="backTop">
        <i class="icon-up2"></i>
        <span class="">返回顶部</span>
    </a>
</div>



<!--script-->
<script src="js/ssologin_1.js"></script>
<script type="text/javascript" src="js/sea_1.js"></script>
<script type="text/javascript" src="js/sea_config_1.js"></script>
<script type="text/javascript">seajs.use("/static/page/"+OP_CONFIG.module+"/"+OP_CONFIG.page);</script>


<script type="text/javascript">
  (function(){
    var imgPic = 'http://static.mukewang.com/static/img/common/siglogo.png',
        text = '我在慕课网WIKI找到一个词条：JS数据间的计算法则——运算符。感觉很有帮助呢！', 
        url = 'http://www.mukewang.com' + window.location.pathname;

    window._bd_share_config = {
        "common": {
            "bdUrl": url,
            "bdSnsKey": {
              'tsina':'2788596354'
            },
            "bdText": text,
            "bdMini": "2",
            "bdMiniList": false,
            "bdPic": imgPic,
            "bdStyle": "0",
            "bdSize": "16"
        },
        "share": {}
    };
    with(document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];
  })();
</script>


<div style="display: none">
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Ff0cfcccd7b1393990c78efdeebff3968' type='text/javascript'%3E%3C/script%3E"));
(function (d) {
window.bd_cpro_rtid="rHT4P1c";
var s = d.createElement("script");s.type = "text/javascript";s.async = true;s.src = location.protocol + "//cpro.baidu.com/cpro/ui/rt.js";
var s0 = d.getElementsByTagName("script")[0];s0.parentNode.insertBefore(s, s0);
})(document);
</script>
<script>
(function(){
    var bp = document.createElement('script');
    bp.src = '//push.zhanzhang.baidu.com/push.js';
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
</div>
</body>
</html>
